package DB;

import java.util.ArrayList;
import Communication.Client;
import Entity.Product;
import Entity.Type;

/** this class asks queries to get and insert product's details from and into the db  */
public class ProductQuery {

	private ArrayList<Product> productList;

	/**constructor
	 * 
	 * @param client
	 */
	public ProductQuery(Client client) 
	{
		productList = new ArrayList<Product>();			
	}
	
	/**function which insert product's details into db */
	public static String InsertProduct(Product Prd) 
	{
		String str= "INSERT INTO products (ProductID,ProductName,Price,Image,Description) VALUES (\"" + Prd.getProductID() +"\" , \"" + Prd.getProductName() + "\",\"" + Prd.getPrice()+"\",\"" + Prd.getPicture() +"\",\"" + Prd.getDescription()+"\")";
		return str;
	}

	/**function which get city all product's details from db */
	public static String getAllProducts()
	{
		String sql = "SELECT ProductName FROM products";
		return sql;
	}
	
	/**function which check if product with selected product id is in db */
	public static String  checkExistProduct(String productID)
	{
		String str= "SELECT * FROM  products WHERE ProductID= "+ "\"" + productID + "\"";
		return str;
	}
	
	/**function which update product's type for this parameters
	 * 
	 * @param client
	 * @param Prd
	 * @param Tp
	 * @return
	 */
	public static String setType(Client client,Product Prd,   Type Tp)
	{
		String str="UPDATE products SET TypeID="+Tp.TypeID+" WHERE ProductID="+Prd.getProductID()+";";
		return str;
	}

	/**functions which check if a field is empty */
	public  boolean isEmpty(String field) 
	{
		if (field.isEmpty())
			return true;
		return false;
	}

	public  boolean isEmptyBool(boolean bool) 
	{
		if (bool)
			return true;
		return false;
	}

}